<?php

namespace Apps\Common\Models;

/**
 * 活动Model
 * @author     chenxiaolin
 * @date        2016年1月19日
 * @version     2.0.0
 * @copyright   Copyright 2016 meelier.com
 */

class Activity extends \PhalconPlus\Database\Model
{

    /**
     *
     * @var integer
     */
    public $activity_id;

    /**
     *
     * @var integer
     */
    public $city_id;

    /**
     *
     * @var integer
     */
    public $activity_type;

    /**
     *
     * @var string
     */
    public $activity_title;

    /**
     *
     * @var string
     */
    public $activity_cover;

    /**
     *
     * @var string
     */
    public $activity_intro;

    /**
     *
     * @var integer
     */
    public $activity_state;

    /**
     *
     * @var string
     */
    public $activity_start_time;

    /**
     *
     * @var string
     */
    public $activity_end_time;

    /**
     *
     * @var string
     */
    public $activity_addtime;
    
    //新增字段
    public $posion_banner;
    
    public $out_link;
    
    public $create_user;
    
    public $views;
    public $comments;
    
    public $activity_update_time;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        $this->hasMany('activity_id', 'Apps\Common\Models\ActivityBeautyParlor', 'activity_id', array('alias' => 'ActivityBeautyParlor'));
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'activity';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return Activity[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return Activity
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * Independent Column Mapping.
     * Keys are the real names in the table and the values their names in the application
     *
     * @return array
     */
    public function columnMap()
    {
        return array(
            'activity_id' => 'activity_id',
            'city_id' => 'city_id',
            'activity_type' => 'activity_type',
            'activity_title' => 'activity_title',
            'activity_cover' => 'activity_cover',
            'activity_intro' => 'activity_intro',
            'activity_state' => 'activity_state',
            'activity_start_time' => 'activity_start_time',
            'activity_end_time' => 'activity_end_time',
            'activity_addtime' => 'activity_addtime',
        	'posion_banner'	=> 'posion_banner',
        	'out_link' => 'out_link',
            'create_user' => 'create_user',
            'views' => 'views',
            'comments' => 'comments',
            'activity_update_time' => 'activity_update_time'
        );
    }

    public function defaultColumns()
    {
        return [
            'activity_state',
            'activity_start_time',
            'activity_end_time',
            'activity_addtime',
            'activity_update_time'
        ];
    }

    /**
     * 增加浏览数
     * @param int $id 活动id
     * @param int $count 增加数量
     */
    /*public static function setViews($id, $count = 100)
    {
        (new Activity())->getReadConnection()->query("UPDATE activity SET views = views + {$count} WHERE activity_id = {$id}");
    }*/

}
